package com.flyfox.component.config;

import com.alibaba.fastjson.JSONObject;
import com.flyfox.jfinal.template.CRUD;
import com.flyfox.jfinal.template.CRUDFactory;
import com.flyfox.jfinal.template.FormType;
import com.flyfox.jfinal.template.InputType;
import com.flyfox.jfinal.template.ModelAttr;
import com.flyfox.jfinal.template.TemplateUtils;
import com.flyfox.modules.hr.model.Organizations;
import com.flyfox.modules.hr.model.Personal;
import com.flyfox.modules.hr.model.Salary;
import com.flyfox.modules.hr.model.SalaryItem;
import com.flyfox.modules.system.user.SysUser;

/**
 * 已支持XMl配置
 * 
 * 2014年9月9日 下午4:39:13 flyfox 330627517@qq.com
 */
public class TableConfig {

	private static CRUDFactory factory = CRUDFactory.instance();

	public static void main(String[] args) {
		init();
		factory.create();
		System.out.println(1);
	}

	public static void init() {
		// 组织机构
		CRUD organ = new CRUD();
		organ.setPrimaryKey("id");
		organ.setUrlKey("organ");
		organ.setName("组织机构");
		organ.setAttr(new ModelAttr().setKey("org_name").setName("姓名").addSearch()
				.setFormTypeVaild("required='required'"));
		organ.setAttr(new ModelAttr().setKey("short_name").setName("简称").setFormTypeVaild("required='required'"));
		organ.setAttr(new ModelAttr().setKey("sort").setName("序号"));
		organ.setAttr(new ModelAttr().setKey("remark").setName("说明").setFormType(FormType.TEXTAREA));
		factory.add(Organizations.class, organ);

		// 人员信息
		CRUD person = new CRUD();
		person.setPrimaryKey("id");
		person.setUrlKey("person");
		person.setName("人员信息");
		person.setAttr(new ModelAttr().setKey("p_name").setName("姓名") //
				.setFormTypeVaild("required='required'").addSearch());
		person.setAttr(new ModelAttr().setKey("p_no").setName("编号").setOperate((byte) 0));

		JSONObject orgName = new JSONObject();
		orgName.put("sql", "select id,org_name from tb_hr_organizations order by sort ");
		orgName.put("key", "id");
		orgName.put("value", "org_name");
		person.setAttr(new ModelAttr().setKey("org_id").setName("组织机构") //
				.setFormType(FormType.SELECT).setFormTypeData(orgName.toJSONString()).addSearch());

		person.setAttr(new ModelAttr().setKey("p_cert").setName("证件号码"));

		String sex = TemplateUtils.radioJson("1", "男", "2", "女");
		person.setAttr(new ModelAttr().setKey("p_sex").setName("性别") //
				.setInputType(InputType.RADIO).setFormTypeData(sex).addSearch());

		person.setAttr(new ModelAttr().setKey("p_birthdate").setName("生日") //
				.setInputType(InputType.DATE));
		person.setAttr(new ModelAttr().setKey("p_country").setName("国家").removeList() //
				.setFormType(FormType.DICT).setFormTypeData("country"));
		person.setAttr(new ModelAttr().setKey("p_education").setName("学历").removeList() //
				.setFormType(FormType.DICT).setFormTypeData("education"));
		person.setAttr(new ModelAttr().setKey("p_nation").setName("民族").removeList() //
				.setFormType(FormType.DICT).setFormTypeData("nation"));
		person.setAttr(new ModelAttr().setKey("p_shool").setName("毕业学校").removeList());
		person.setAttr(new ModelAttr().setKey("p_email").setName("email").removeList());

		person.setAttr(new ModelAttr().setKey("p_marry").setName("已婚").removeList() //
				.setInputType(InputType.RADIO).setFormTypeData(TemplateUtils.radioJson("1", "是", "2", "否")));

		person.setAttr(new ModelAttr().setKey("p_phone").setName("手机号"));
		person.setAttr(new ModelAttr().setKey("p_tel").setName("电话").removeList());
		person.setAttr(new ModelAttr().setKey("salary").setName("基本工资"));
		person.setAttr(new ModelAttr().setKey("salary_bank").setName("工资银行").setFormType(FormType.DICT)
				.setFormTypeData("salary_bank").removeList());
		person.setAttr(new ModelAttr().setKey("salary_card").setName("工资卡号").removeList());
		person.setAttr(new ModelAttr().setKey("remark").setName("备注").setFormType(FormType.TEXTAREA));
		factory.add(Personal.class, person);

		// 薪酬项目
		CRUD salaryItem = new CRUD();
		salaryItem.setPrimaryKey("id");
		salaryItem.setUrlKey("salaryitem");
		salaryItem.setName("薪酬项目");
		salaryItem.setAttr(new ModelAttr().setKey("item_name").setName("名称").addSearch()
				.setFormTypeVaild("required='required'"));
		salaryItem.setAttr(new ModelAttr().setKey("item_short_name").setName("简称"));
		salaryItem.setAttr(new ModelAttr().setKey("item_no").setName("对应编号"));
		salaryItem.setAttr(new ModelAttr().setKey("item_type").setName("项目类型") //
				.setFormType(FormType.DICT).setFormTypeData("item_type").addSearch());
		salaryItem.setAttr(new ModelAttr().setKey("org_id").setName("组织机构") //
				.setFormType(FormType.SELECT).setFormTypeData(orgName.toJSONString()).setOperate((byte) 0));
		salaryItem.setAttr(new ModelAttr().setKey("sort").setName("排序号"));
		salaryItem.setAttr(new ModelAttr().setKey("is_plus").setName("类型") //
				.setFormType(FormType.SELECT) //
				.setFormTypeData(TemplateUtils.radioJson("1", "正", "2", "负", "3", "其他")));
		salaryItem.setAttr(new ModelAttr().setKey("is_tax").setName("计税") //
				.setInputType(InputType.RADIO).setFormTypeData(TemplateUtils.radioJson("1", "是", "2", "否")));
		salaryItem.setAttr(new ModelAttr().setKey("is_show").setName("展示") //
				.setInputType(InputType.RADIO).setFormTypeData(TemplateUtils.radioJson("1", "是", "2", "否")));
		salaryItem.setAttr(new ModelAttr().setKey("remark").setName("说明").setFormType(FormType.TEXTAREA));
		factory.add(SalaryItem.class, salaryItem);

		// 薪酬管理
		CRUD salary = new CRUD();
		salary.setPrimaryKey("id");
		salary.setUrlKey("salary");
		salary.setName("薪酬管理");
		salary.setAttr(new ModelAttr().setKey("salary_month").setName("月份").setOperate((byte) 0).addSearch());
		salary.setAttr(new ModelAttr().setKey("p_name").setName("姓名").addSearch());
		salary.setAttr(new ModelAttr().setKey("org_id").setName("组织机构") //
				.setFormType(FormType.SELECT).setFormTypeData(orgName.toJSONString()).addSearch());
		factory.add(Salary.class, salary);

		// 用户管理
		CRUD user = new CRUD();
		user.setPrimaryKey("userid");
		user.setUrlKey("user");
		user.setName("用户");
		user.setAttr(new ModelAttr().setKey("username").setName("登陆名").addSearch()
				.setFormTypeVaild("required='required'"));
		user.setAttr(new ModelAttr().setKey("realname").setName("真实姓名").addSearch());
		factory.add(SysUser.class, user);
	}
}
